home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Magazine 28 Bonus / CDRomMagazine-SoftKey-ArtPassion-FrenchVersion-Win31Mac.bin / data / cngrkpl.dir / 00120_Script_GAME HANDLERS < prev    next >
Text File  |  1996-05-30  |  8KB  |  250 lines

  1. -- ---------------------------------------------------------------
  2. -- Handler goldenSectionInPlace returns true if the user placed the
  3. -- outline in a proper place and false otherwise.
  4.  
  5. on goldenSectionInPlace
  6.   global outline, goldenSectionInfo, sectionName, sectionRect
  7.   
  8.   set markerName = the frameLabel
  9.   repeat with i = 1 to the number of lines in goldenSectionInfo
  10.     set lineInfo = line i of goldenSectionInfo
  11.     set sectionName = item 1 of lineInfo
  12.     
  13.     if goldenSectionPlaced(sectionName) then
  14.       returnOutlineToPlace
  15.     else -- an outline was not placed around the piece
  16.       setSectionRect(lineInfo)
  17.       if (markerName = item 2 of lineInfo) and (inside(point(the mouseH,the mouseV), sectionRect)) then
  18.         return TRUE
  19.       end if
  20.     end if
  21.   end repeat
  22. end
  23.  
  24. -- ---------------------------------------------------------------
  25. -- Handler doMatchGoldenSection
  26.  
  27. on doMatchGoldenSection
  28.   global currentPlacedPiece, sectionName, sectionRect
  29.   
  30.   -- place the piece on the board
  31.   putOutlineAroundPiece(sectionName)
  32.   
  33.   --  set the castNum of sprite currentPlacedPiece = the number of cast (sectionName && "GoldenSection")
  34.   --  spriteBox currentPlacedPiece, rectLeft(sectionRect), rectTop(sectionRect), rectRight(sectionRect), rectBottom(sectionRect)
  35.   returnOutlineToPlace
  36.   updateStage
  37.   
  38.   updateCurrentPlacedPiece
  39.   updatePlacedGoldenSectionsList(sectionName)
  40.   updateFramePlacedPieces(sectionName)
  41.   updateScore
  42. end
  43.  
  44. -- ---------------------------------------------------------------
  45. -- Handler returnOutlineToPlace 
  46.  
  47. on returnOutlineToPlace
  48.   global outline, outlineH, outlineV
  49.   
  50.   set the locH of sprite outline = outlineH
  51.   set the locV of sprite outline = outlineV
  52. end
  53.  
  54. -- -----------------------------------------------------------
  55. -- Handler updatePlacedGoldenSectionsList adds the just placed
  56. -- outline to the global variable placedGoldenSectionsList.
  57.  
  58. on updatePlacedGoldenSectionsList whichSection
  59.   global placedGoldenSectionsList
  60.   
  61.   add(placedGoldenSectionsList, whichSection)
  62. end
  63.  
  64. -- -----------------------------------------------------------
  65. -- Handler goldenSectionPlaced returns true if the given piece
  66. -- was already placed and false otherwise
  67.  
  68. on goldenSectionPlaced sectionName
  69.   global placedGoldenSectionsList
  70.   
  71.   return getPos(placedGoldenSectionsList, sectionName)
  72. end
  73.  
  74. -- ---------------------------------------------------------------
  75. -- Handler dragOutline 
  76.  
  77. on dragOutline whichPiece, checkHandler, matchHandler
  78.   -- if they clicked on whichPiece (checked by the sprite number of the clickOn)
  79.   
  80.   if (the clickOn = whichPiece) then
  81.     flashLightBulbs
  82.     if placedASection() then fadeLastPlacedSection
  83.     TrackAndCheck(whichPiece, checkHandler, matchHandler)
  84.   end if
  85. end
  86.  
  87. -- ---------------------------------------------------------------
  88. -- Handler placedASection returns TRUE if the user found a golden
  89. -- section already and FALSE otherwise.
  90.  
  91. on placedASection
  92.   global placedGoldenSectionsList
  93.   
  94.   return count(placedGoldenSectionsList)
  95. end
  96.  
  97. -- ---------------------------------------------------------------
  98. -- Handler fadeLastPlacedSections sets the color of the last placed
  99. -- outline to fade a bit and not confuse the screen.
  100.  
  101. on fadeLastPlacedSection
  102.   global currentPlacedPiece
  103.   
  104.   set the foreColor of sprite (currentPlacedPiece-1) to 80 -- last placed piece
  105. end
  106.  
  107. -- ---------------------------------------------------------------
  108. -- Handler flashLightBulbs flashes the lightbulbs when the user
  109. -- clicks on the outline. 
  110.  
  111. on flashLightBulbs
  112.   global rightBulb, leftBulb
  113.   
  114.   -- The bulbs flash one at a time:
  115.   -- First the right
  116.   flashOneBulb(rightBulb)
  117.   
  118.   repeat with i = 1 to 6
  119.     -- now the right and left will alternate
  120.     flashOneBulb(rightBulb)
  121.     flashOneBulb(leftBulb)
  122.   end repeat
  123.   
  124.   --  Finally, return the right to original
  125.   flashOneBulb(rightBulb)
  126. end
  127.  
  128. -- ---------------------------------------------------------------
  129. -- Handler flashOneBulb 
  130.  
  131. on flashOneBulb whichBulb
  132.   set bulbCastName = the name of cast the castNum of sprite whichBulb
  133.   set bulbStatus = value(word 2 of bulbCastName)
  134.   set newBulbCast = word 1 of bulbCastName && string(not(bulbStatus))
  135.   set the castNum of sprite whichBulb = the number of cast newBulbCast
  136.   updateStage
  137. end
  138.  
  139. -- ---------------------------------------------------------------
  140. -- Handler goNextGSGameFrame goes to the next frame in the game
  141.  
  142. on goNextGSGameFrame whichFrame
  143.   -- remove the outlines of the last frame
  144.   global currentPlacedPiece, firstPlacedOutline, GSFrame1PlacedList
  145.   global GSFrame2PlacedList, goldenSectionInfo
  146.   
  147.   repeat with i = firstPlacedOutline to currentPlacedPiece
  148.     removeFromStage(i)
  149.   end repeat
  150.   
  151.   updateStage
  152.   -- reInitialize currentPlacedPiece
  153.   initializeCurrentPlacedPiece
  154.   
  155.   -- put back the placed outlines of the new frame
  156.   set placedList = value("GSFrame" & whichFrame & "PlacedList")
  157.   
  158.   repeat with i = 1 to count(placedList)
  159.     set sectionName = getAt(placedList,i)
  160.     repeat with j = 1 to the number of lines in goldenSectionInfo
  161.       if (sectionName = item 1 of line j of goldenSectionInfo) then
  162.         -- place that piece on stage
  163.         setSectionRect(line j of goldenSectionInfo)
  164.         putOutlineAroundPiece(sectionName)
  165.         
  166.         updateCurrentPlacedPiece
  167.         exit repeat -- replace next piece 
  168.       end if
  169.     end repeat
  170.   end repeat
  171. end
  172.  
  173.  
  174. on updateFramePlacedPieces sectionName
  175.   global GSFrame2PlacedList, GSFrame1PlacedList
  176.   
  177.   if (the frameLabel = "GS1") then
  178.     add(GSFrame1PlacedList, sectionName)
  179.   else if (the frameLabel = "GS2") then
  180.     add(GSFrame2PlacedList, sectionName)
  181.   end if
  182. end
  183.  
  184. -- ---------------------------------------------------------------
  185. -- Handler initializeCurrentPlacedPiece sets the global varibale
  186. -- currentPlacedPiece to the value of the global variable
  187. -- firstPlacedOutline.
  188.  
  189. on initializeCurrentPlacedPiece
  190.   global currentPlacedPiece, firstPlacedOutline
  191.   set currentPlacedPiece = firstPlacedOutline
  192. end
  193.  
  194. -- ---------------------------------------------------------------
  195. -- Handler setSectionRect sets the global variable sectionRect to
  196. -- the rect of the piece in the given line of data.
  197.  
  198. on setSectionRect lineInfo
  199.   global sectionRect
  200.   
  201.   set sectionLeft = value(word 1 of item 3 of lineInfo)
  202.   set sectionTop = value(word 2 of item 3 of lineInfo)
  203.   set sectionRight = value(word 3 of item 3 of lineInfo)
  204.   set sectionBottom = value(word 4 of item 3 of lineInfo)
  205.   
  206.   set sectionRect = rect(sectionLeft, sectionTop, sectionRight, sectionBottom)
  207. end
  208.  
  209. -- ---------------------------------------------------------------
  210. -- Handler putOutlineAroundPiece 
  211.  
  212. on putOutlineAroundPiece sectionName
  213.   global currentPlacedPiece, sectionRect
  214.   
  215.   set the castNum of sprite currentPlacedPiece = the number of cast (sectionName && "GoldenSection")
  216.   spriteBox currentPlacedPiece, rectLeft(sectionRect), rectTop(sectionRect), rectRight(sectionRect), rectBottom(sectionRect)
  217. end
  218.  
  219. -- ---------------------------------------------------------------
  220. -- Handler updateScore updates the score whenever an outline has
  221. -- been correctly placed around something with a golden section.
  222.  
  223. on updateScore
  224.   set currentScore = value(the text of field "score")
  225.   set currentScore = currentScore + 1
  226.   put currentScore into field "score"
  227.   if currentScore  = 19 then success
  228. end
  229.  
  230.  
  231. -- ---------------------------------------------------------------
  232. -- Handler playNarration plays the given narration. If the narration is
  233. -- an external soundFile it _has_ to have extension ".AIF" it uses sound playfile.
  234. -- command Otherwise it assumes it is an imported castmember and uses "puppetSound"
  235.  
  236. on playNarration aNarration
  237.   global soundFolder
  238.   set suffix = getSuffix(aNarration)
  239.   if suffix = ".AIF" then sound playFile 1,the pathName & soundFolder & aNarration
  240.   else puppetSound aNarration
  241.   
  242.   waitsound 1
  243. end
  244.  
  245.  
  246. on getSuffix aString
  247.   set r = char (the number of chars in aString - 3) to (the number of chars i